package com.yihaodian.server;

import com.yihaodian.api.search.SearchException;

public abstract class AbstractLifecycleService implements LifeCycleService {
	protected final Lifecycle lifecycle = new Lifecycle();

	public void startup() throws SearchException {
		if (!lifecycle.canMoveToStarted()) {
			return;
		}

		doStart();
		lifecycle.moveToStarted();
	}

	protected abstract void doStart() throws SearchException;

	@Override
	public void shutdown() throws SearchException {
		if (!lifecycle.canMoveToStopped()) {
			return;
		}

		lifecycle.moveToStopped();
		doStop();
	}

	protected abstract void doStop() throws SearchException;

}
